package com.web.mapper;
 
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.web.pojo.User;

public interface UserMapper {
	
    /**
     * 添加用户  
     * @param user
     * @return boolean
     */
	@Insert("INSERT INTO user(mailBox,roleName,userName,userPassword,userPhone,userSex,groupName,areaName) VALUES (#{mailBox},#{roleName},#{userName},#{userPassword},#{userPhone},#{userSex},#{groupName},#{areaName})")
    public boolean UserAdd(User user);
    /**
     * 根据邮箱删除用户
     * @param mailBox
     * @return boolean
     */
	@Delete("delete from user where mailBox= #{mailBox}")
    public boolean UserDeleteByMailBox(String mailBox);
	/**
	 * 根据邮箱修改用户密码
	 * @param mailBox
	 * @param userPassword
	 * @return boolean
	 */
	@Update("update user set userPassword=#{userPassword} where mailBox= #{mailBox}")
    public boolean UserUpdetaByMailBox(@Param("mailBox")String mailBox,@Param("userPassword")String userPassword);
	/**
	 * 更新用户信息 
	 * @param user
	 * @return boolean
	 */
    @Update("update user set userName=#{userName},userPhone=#{userPhone},userSex=#{userSex} where mailBox= #{mailBox}")
    public boolean UserUpdate(User user);
    /**
     * 用户登入
     * @param mailBox
     * @param userPassword
     * @return User
     */
    @Select("SELECT mailBox,roleName,userName,userPhone,userSex,groupName,areaName FROM user WHERE mailBox= #{mailBox} AND userPassword= #{userPassword}")
    public User UserGetByMailBoxAndPassword(@Param("mailBox")String mailBox,@Param("userPassword")String userPassword);
    /**
     * 用户名查询
     * @param userName
     * @return User
     */
    @Select("SELECT mailBox,roleName,userName,userPhone,userSex,groupName,areaName FROM user WHERE userName= #{userName}")
    public User UserGetByUserName(String userName);
    /**
     * 小组名称查询
     * @param groupName
     * @return List<User>
     */
    @Select("SELECT mailBox,roleName,userName,userPhone,userSex,groupName,areaName FROM user WHERE groupName= #{groupName}")
    public List<User> UserGetBygGoupName(String groupName);
    /**
     * 所属地区名称查询
     * @param areaName
     * @return List<User>
     */
    @Select("SELECT mailBox,roleName,userName,userPhone,userSex,groupName,areaName FROM user WHERE areaName= #{areaName}")
    public List<User> UserGetByAreaName(String areaName);
    /**
     * 查询所有用户
     * @return List<User>
     */
    @Select("select mailBox,roleName,userName,userPhone,userSex,groupName,areaName from user")
    public List<User> UserList();
    /**
     * 用户统计  
     * @return int
     */
    @Select("select count(0) from user")
    public int UserCount();
    
}